import request from '@/utils/request'
// 登录请求
export const loginAPI = ({ account, password }) => {
  return request({
    url: '/member-api/api/v1/members/pass/login',
    method: 'POST',
    data: {
      account,
      password
    }
  })
}
export const getMemberApi = (id) => {
  return request({
    url: '/member-api/api/v1/members/findById',
    method: 'GET',
    params: {
      id
    }
  })
}

import { jwtDecode } from 'jwt-decode'

// 解析JWT中的用户ID
export const getUserIdFromToken = (token) => {
  try {
    const decoded = jwtDecode(token)
    return decoded.userId
  } catch (error) {
    console.error('JWT解码失败:', error)
    return null
  }
}
export const updateMemberInfoAPI = (data) => {
  return request({
    url: '/member-api/api/v1/members',
    method: 'PUT',
    data
  })
}
// 猜你喜欢数据请求
export const getLikeListAPI = ({ limit = 4 }) => {
  return request({
    url: '/goods/relevant',
    params: {
      limit
    }
  })

}

export const getAddressTree = () => {
  return request({
    url: '/address-api/api/v1/addresses/tree',
    method: 'GET'

  })
}

export const uploadPortrait = (formData) => {
  return request({
    url: '/member-api/api/v1/members/upload',
    method: 'POST',
    data: formData
  })
}